$(function () {
    $("body").on("click",".fwwd-didianflxz",function () {
        $(this).addClass("fwwd-didianflxzActice").siblings().removeClass("fwwd-didianflxzActice");
        if ($(this).text()!=="全部"){
        	if($(".fwwd-yxzDiv").find(".yxztitle.top").length==0){
        		var div = $("<div class='yxztitle top'><span class='topzhid'>"+$(this).text()+"</span> <img src='static/img/X.png' class='fwwd-close'></div>").appendTo(".fwwd-yxzDiv");
        	}else{
        		$(".topzhid").text($(this).text())
        	}
        		
        	
            var streetId = $(this).attr("id");
            if ($(".fwwd-didianflDiv.fwwd-didianflDivActive").text()!=="全部"){
                var orgProperty = $(".jg.jdxz").attr("id");
                $.ajax({
                    url:"app/queryBranch.do",
                    type:"POST",
                    data:{streetId:streetId,orgProperty:orgProperty},
                    dataType:"JSON",
                    success:function(json){
                        if (json.code==0){
                            $(".wdTable").children().remove();
                            $("body").css("width", $(window).width());
                            $(json.data).each(function (i,o) {
                            	var tr = $("<tr><td>"+o.street+"</td><td>"+o.corpName+"</td><td>"+o.orgName+"</td><td>"+o.address+"</td><td>"+o.telephone+"</td><td>"+o.date+"</td><td>"+o.serviceTypeName+"</td></tr>").appendTo(".wdTable");
                            })
                        }else{
                            alert(json.message);
                            $(".wdTable").children().remove();
                        }
                    }
                })
            }else{
                $.ajax({
                    url:"app/queryBranch.do",
                    type:"POST",
                    data:{streetId:streetId},
                    dataType:"JSON",
                    success:function(json){
                        if (json.code==0){
                            $(".wdTable").children().remove();
                            $("body").css("width", $(window).width());
                            $(json.data).each(function (i,o) {
                            	var tr = $("<tr><td>"+o.street+"</td><td>"+o.corpName+"</td><td>"+o.orgName+"</td><td>"+o.address+"</td><td>"+o.telephone+"</td><td>"+o.date+"</td><td>"+o.serviceTypeName+"</td></tr>").appendTo(".wdTable");
                            })
                        }else{
                            alert(json.message);
                            $(".wdTable").children().remove();
                        }
                    }
                })
            }
        }else{
        	$(".fwwd-yxzDiv").find(".yxztitle.top").remove();
            if ($(".fwwd-didianflDiv.fwwd-didianflDivActive").text()!=="全部"){
                var orgProperty = $(".fwwd-didianflDiv.fwwd-didianflDivActive").attr("id");
                $.ajax({
                    url:"app/queryBranch.do",
                    type:"POST",
                    data:{orgProperty:orgProperty},
                    dataType:"JSON",
                    success:function(json){
                        if (json.code==0){
                            $(".wdTable").children().remove();
                            $("body").css("width", $(window).width());
                            $(json.data).each(function (i,o) {
                            	var tr = $("<tr><td>"+o.street+"</td><td>"+o.corpName+"</td><td>"+o.orgName+"</td><td>"+o.address+"</td><td>"+o.telephone+"</td><td>"+o.date+"</td><td>"+o.serviceTypeName+"</td></tr>").appendTo(".wdTable");
                            })
                        }else{
                            alert(json.message);
                            $(".wdTable").children().remove();
                        }
                    }
                })
            }else{
                getWD();
            }
        }
    });

    $("body").on("click",".fwwd-didianflDiv",function () {
        $(this).addClass("fwwd-didianflDivActive").siblings().removeClass("fwwd-didianflDivActive");
        if ($(this).text()!=="全部"){
        	if($(".fwwd-yxzDiv").find(".yxztitle.bot").length==0){
        		var div = $("<div class='yxztitle bot'><span class='botzhid'>"+$(this).text()+"</span> <img src='static/img/X.png' class='fwwd-close'></div>").appendTo(".fwwd-yxzDiv");
        	}else{
        		$(".botzhid").text($(this).text())
        	}
            var orgProperty= $(this).attr("id");
            if ($(".fwwd-didianflxz.fwwd-didianflxzActice").text()!=="全部"){
                var streetId = $(".fwwd-didianflxz.fwwd-didianflxzActice").attr("id");
                $.ajax({
                    url:"app/queryBranch.do",
                    type:"POST",
                    data:{streetId:streetId,orgProperty:orgProperty},
                    dataType:"JSON",
                    success:function(json){
                        if (json.code==0){
                            $(".wdTable").children().remove();
                            $("body").css("width", $(window).width());
                            $(json.data).each(function (i,o) {
                            	var tr = $("<tr><td>"+o.street+"</td><td>"+o.corpName+"</td><td>"+o.orgName+"</td><td>"+o.address+"</td><td>"+o.telephone+"</td><td>"+o.date+"</td><td>"+o.serviceTypeName+"</td></tr>").appendTo(".wdTable");
                            })
                        }else{
                            alert(json.message);
                            $(".wdTable").children().remove();
                        }
                    }
                })
            }else{
                $.ajax({
                    url:"app/queryBranch.do",
                    type:"POST",
                    data:{orgProperty:orgProperty},
                    dataType:"JSON",
                    success:function(json){
                        $(".wdTable").children().remove();
                        $("body").css("width", $(window).width());
                        if (json.code==0){
                            $(json.data).each(function (i,o) {
                            	var tr = $("<tr><td>"+o.street+"</td><td>"+o.corpName+"</td><td>"+o.orgName+"</td><td>"+o.address+"</td><td>"+o.telephone+"</td><td>"+o.date+"</td><td>"+o.serviceTypeName+"</td></tr>").appendTo(".wdTable");
                            })
                        }else{
                            alert(json.message);
                            $(".wdTable").children().remove();
                        }
                    }
                })
            }
        }else{
        	$(".fwwd-yxzDiv").find(".yxztitle.bot").remove();
            if ($(".fwwd-didianflxz.fwwd-didianflxzActice").text()!=="全部"){
                var streetId = $(".fwwd-didianflxz.fwwd-didianflxzActice").attr("id");
                $.ajax({
                    url:"app/queryBranch.do",
                    type:"POST",
                    data:{streetId:streetId},
                    dataType:"JSON",
                    success:function(json){
                        if (json.code==0){
                            $(".wdTable").children().remove();
                            $("body").css("width", $(window).width());
                            $(json.data).each(function (i,o) {
                            	var tr = $("<tr><td>"+o.street+"</td><td>"+o.corpName+"</td><td>"+o.orgName+"</td><td>"+o.address+"</td><td>"+o.telephone+"</td><td>"+o.date+"</td><td>"+o.serviceTypeName+"</td></tr>").appendTo(".wdTable");
                            })
                        }else{
                            alert(json.message);
                            $(".wdTable").children().remove();
                        }
                    }
                })
            }else{
               getWD();
            }
        }

    })

    $("body").on("click",".yxztitle.top",function () {
        $("#topall").click();
    })
    $("body").on("click",".yxztitle.bot",function () {
        $("#botall").click();
    })
    getWD();
    pickjiedao();
    pickfuwu();
})



function getWD() {
    $.ajax({
       url:"front/queryBranch.do",
       type:"GET",
       dataType:"JSON",
       success:function (json) {
    	   $(".wdTable").children().remove();
           $("body").css("width", $(window).width());
           $(json.data).each(function (i,o) {
               var tr = $("<tr><td>"+o.street+"</td><td>"+o.corpName+"</td><td>"+o.orgName+"</td><td>"+o.address+"</td><td>"+o.telephone+"</td><td>"+o.date+"</td><td>"+o.serviceTypeName+"</td></tr>").appendTo(".wdTable");
           })
       }
    })
}

function pickjiedao() {
    $.ajax({
        url:"app/queryAllBranchStreet.do",
        type:"GET",
        dataType:"JSON",
        success:function(json){
            if (json.code==0){
                if (json.data.length!==0){
                    $(json.data).each(function (i, o) {
                        var jd = $("<div class='fwwd-didianflxz' id='"+o.id+"'>"+o.name+"</div>").appendTo(".jiedao");
                    })
                }
            }else{
                alert(json.message);
            }
        }
    })

}
function pickfuwu() {
    $.ajax({
        url: "app/queryOrgProperty.do",
        type: "GET",
        dataType: "JSON",
        success: function (json) {
            if (json.code == 0) {
                if (json.data.length !== 0) {
                    var jdArr = [];
                    $(json.data).each(function (i, o) {
                        var jd = $("<div class='fwwd-didianflDiv' id='"+o.id+"'>"+o.name+"</div>").appendTo(".jigou");
                    })
                }
            }
        }

    })

}